import {fhirSearchApi,fhirHistoryApi,fhirDeleteApi} from "../../api/modules/fhirApi";
import {createProcedureRequestApi, updateProcedureRequestApi} from "../../api/modules/procedureRequestApi";

export default {
  state: {
    procedureRequestList: []
  },
  mutations: {
    setProcedureRequestListList(state, data) {
      state.procedureRequestList = data;
    }
  },
  actions: {
    getProcedureRequestList({commit, rootState}, params) {
      return fhirSearchApi(params).then(res => {
        console.log(res)
        commit('setProcedureRequestListList', res.data.entry ? res.data.entry : [{resource:res.data}])
      }).catch(res =>{
        commit('setProcedureRequestListList',[]);
      })
    },
    getHistoryProcedureRequestList({commit, rootState}, params) {
      return fhirHistoryApi(params).then(res => {
        commit('setProcedureRequestListList', res.data.entry ? res.data.entry : [{resource:res.data}])
      })
    },
    updateProcedureRequest({commit, rootState}, params) {
      return updateProcedureRequestApi(params);
    },
    createProcedureRequest({commit, rootState}, params) {
      return createProcedureRequestApi(params);
    },
    deleteProcedureRequest({commit, rootState}, params) {
      return fhirDeleteApi(params);
    }
  }
}
